#include <iostream>

using namespace std;

typedef long long LL;
const int N = 21e5 + 10;

LL dp[N];
int n;
LL a[N];
int main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	LL ret;	
	dp[0] = ret = a[0];
	for(int i = 1; i < n; i++)
	{
		dp[i] = max(a[i],dp[i-1] + a[i]);
		ret = max(ret,dp[i]);
	}
	cout << ret;
	return 0;
}
